﻿package javase.socket.net;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

public class URLReader {
	
	public static void main(String[] args) throws Exception {
		// 声明抛出所有例外

		URL tirc = new URL("http://www.google.com/");

		// 构建一URL对
		BufferedReader in = new BufferedReader(new InputStreamReader(tirc.openStream()));
		// 使用openStream得到一输入流并由此构造一个BufferedReader对象
		String inputLine;
		while ((inputLine = in.readLine()) != null){
			// 从输入流不断的读数据，直到读完为止
			System.out.println(inputLine);
		}
		// 把读入的数据打印到屏幕上
		in.close(); // 关闭输入流
		}
}

/*
  <html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title><style><!--
body,td,a,p,.h{font-family:arial,sans-serif}
.h{font-size:20px}
.h{color:#3366cc}
.q{color:#00c}
#gbar{float:left;font-weight:bold;height:22px;padding-left:2px}#gbh{border-top:1px solid #c9d7f1;font-size:0;height:0;position:absolute;right:0;top:24px;width:200%}#gbi{background:#fff;border:1px solid;border-color:#c9d7f1 #36c #36c #a2bae7;font-size:13px;top:24px;z-index:1000}#guser{padding-bottom:7px !important}#gbar,#guser{font-size:13px;padding-top:1px !important}.gb1,.gb3{display:inline;height:22px;margin-right:1em;vertical-align:top}#gbi,.gb2{display:none;position:absolute;width:7em}.gb2{z-index:1001}#gbar a,#gbar a:active,#gbar a:visited{color:#00c;font-weight:normal}.gb2 a,.gb3 a{text-decoration:none}.gb2 a{display:block;padding:.2em .5em}#gbar .gb2 a:hover{background:#36c;color:#fff}--></style>
<script>
<!--
function sf(){document.f.q.focus();}
window.gbar={};(function(){function z(a,d,b){var c="on"+d;if(a.addEventListener){a.addEventListener(d,b,false)}else if(a.attachEvent){a.attachEvent(c,b)}else{var e=a[c];a[c]=function(){var f=e.apply(this,arguments),n=b.apply(this,arguments);return f==undefined?n:(n==undefined?f:n&&f)}}};var o=window,s=o.location,x=s.search,w=s.protocol,m=document,i="",q,u="",h,g,j=o.gbar,r="wivnlmzbjpcoegz0tqfys",l;function p(a){return escape(unescape(a.replace(/\+/g," "))).replace(/\+/g,"%2B")}function t(a){return g[a].firstChild.tagName=="A"}function k(a){return x.match("[?&]("+a+"=)([^&#]*)")}j.init=function(){var a=0,d,b="affdom,channel,client,hl,hs,ie,lr,ned,oe,og,rls,rlz".split(","),c=k("as_q"),e=k("q");q=k("near");g=m.getElementById("gbar").getElementsByTagName("div");e&&(i=e[2])&&c&&(i+="+");c&&(i+=c[2]);while(t(a++)){}l=r.charAt(a-1);for(a=0;b[a];a++){d=k(b[a]);d&&(u+="&"+d[1]+p(d[2]))}for(a=0;g[a];a++){t(a)&&y(a)}h=m.getElementById("gbi");z(m,"click",j.close)};function y(a){var d=g[a].firstChild,b=d.href+(d.href.match("[?]")?"&":"?"),c=r.charAt(a);if(c!="z"){b+="tab="+l+c;if("com".indexOf(c)>=0){b=b.replace("http:",w)}else{b+=u;if(i){b+="&q="+p(i);q&&l=="l"&&(b+="+near%3A+"+p(q[2]))}}}d.href=b}function v(a,d,b){a.display=a.display=="block"?"none":"block";a.left=d+"px";a.top=b+"px"}j.tg=function(a){var d=0,b,c,e,f=0;a=a?a:o.event;a.cancelBubble=true;for(;h&&g[f];f++){c=g[f];e=c.className;if(e=="gb3"){b=c.offsetLeft;while(c=c.offsetParent){b+=c.offsetLeft}v(h.style,b,24)}else if(e=="gb2"){c.id=="gbar"+l&&(c.style.padding=".2em .5em");v(c.style,b+1,25+d);d+=20}}h.style.height=d+"px"};j.close=function(a){h&&h.style.display=="block"&&j.tg(a)};})();// -->
</script>
</head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="sf();if(document.images){new Image().src='/images/nav_logo3.png'}" topmargin=3 marginheight=3><div id=gbar><nobr><div class=gb1>Web</a></div><div class=gb1><a href=http://images.google.com/imghp>Images</a></div><div class=gb1><a href=http://video.google.com/>Video</a></div><div class=gb1><a href=http://news.google.com/nwshp>News</a></div><div class=gb1><a href=http://maps.google.com/maps>Maps</a></div><div class=gb1><a href=http://mail.google.com/mail>Gmail</a></div><div class=gb3><a href=http://www.google.com/intl/en/options/ onclick="this.blur();gbar.tg(event);return false"><u>more</u> <span style=font-size:11px>&#9660;</span></a></div><div class=gb2><a href=http://blogsearch.google.com/>Blog Search</a></div><div class=gb2><a href=http://www.blogger.com/>Blogger</a></div><div class=gb2><a href=http://books.google.com/bkshp>Books</a></div><div class=gb2><a href=http://www.google.com/calendar>Calendar</a></div><div class=gb2><a href=http://docs.google.com/>Documents</a></div><div class=gb2><a href=http://finance.google.com/finance>Finance</a></div><div class=gb2><a href=http://groups.google.com/grphp>Groups</a></div><div class=gb2><a href=http://labs.google.com/>Labs</a></div><div class=gb2><a href=http://www.orkut.com/>Orkut</a></div><div class=gb2><a href=http://www.google.com/ptshp>Patents</a></div><div class=gb2><a href=http://picasaweb.google.com/home>Photos</a></div><div class=gb2><a href=http://www.google.com/prdhp>Products</a></div><div class=gb2><a href=http://www.google.com/reader>Reader</a></div><div class=gb2><a href=http://scholar.google.com/schhp>Scholar</a></div></nobr></div><iframe frameborder=0 id=gbi scrolling=no></iframe>
<div id=gbh></div><script>window.gbar&&gbar.init()</script><div align=right id=guser style="font-size:84%;padding-bottom:4px" width=100%><nobr><a href="/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den&usg=AFQjCNEj49wK5T88bDwGcaZsW52jiYwJwg">iGoogle</a>&nbsp;|&nbsp;<a href="https://www.google.com/accounts/Login?continue=http://www.google.com/&hl=en">Sign in</a></nobr></div><center><br id=lgpd><img alt="Google" height=110 src="/intl/en_ALL/images/logo.gif" width=276><br><br><form action="/search" name=f><table cellpadding=0 cellspacing=0><tr valign=top><td width=25%>&nbsp;</td><td align=center nowrap><input name=hl type=hidden value=en><input type=hidden name=ie value="ISO-8859-1"><input maxlength=2048 name=q size=55 title="Google Search" value=""><br><input name=btnG type=submit value="Google Search"><input name=btnI type=submit value="I'm Feeling Lucky"></td><td nowrap width=25%><font size=-2>&nbsp;&nbsp;<a href=/advanced_search?hl=en>Advanced Search</a><br>&nbsp;&nbsp;<a href=/preferences?hl=en>Preferences</a><br>&nbsp;&nbsp;<a href=/language_tools?hl=en>Language Tools</a></font></td></tr></table></form><br><br><font size=-1><a href="/intl/en/ads/">Advertising&nbsp;Programs</a> - <a href="/services/">Business Solutions</a> - <a href="/intl/en/about.html">About Google</a> - <b><a href=http://www.google.cn/>Go to Google China</a></b></font><p><font size=-2>&copy;2007 Google</font></p></center></body></html>

 */
